#ifndef MYTCPSOCKET_H
#define MYTCPSOCKET_H
#include <QTcpSocket>

enum class SensorType {
  TEMP_WET = 1 << 1,
  CO2 = 1 << 2,
  LUX = 1 << 3,
  UVs = 1 << 4,
  FRAG = 1 << 5,
  CH4 = 1 << 6,
  FIRE = 1 << 7,
  BODY = 1 << 8,

  TEST_SEN = 0,

  ALL_SENSOR = TEMP_WET | CO2 | LUX | UVs | FRAG | CH4 | FIRE | BODY
};

enum class ExcuteType;

class MyTcpSocket : public QTcpSocket {
  Q_OBJECT
public:
  explicit MyTcpSocket(QObject *parent = nullptr);
  /**
   * @brief 传感器上行数据发送
   * @param type 传感器类型
   * @param value1 值1
   * @param value2 值2
   */
  void send_sensor_data(SensorType type, double value1, double value2 = 0.0);

  void send_excute_data(ExcuteType type, double value1, double value2 = 0.0);

signals:
  void socketDisconnected(QThread *th);

protected slots:
  void readyReadSlot();
  void disconnectedSlot(); //捕获断开信息

protected:
  void handleData(QByteArray data);
  /**
   * @brief 下行执行器数据发送
   * @param data
   */
  void handleFrame(QByteArray data);
  QByteArray temp;

private:
  static MyTcpSocket *instance;
};

#ifndef SG_TCPSOCKET
#define SG_TCPSOCKET(parent) singleton<MyTcpSocket>::getInstance(parent)
#endif

#endif // MYTCPSOCKET_H
